package com.etc.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.etc.entity.Dynamic;
import com.etc.entity.Friend;
import com.etc.entity.Orders;
import com.etc.entity.Travels;
import com.etc.service.DynamicService;
import com.etc.service.FriendService;
import com.etc.service.OrderService;
import com.etc.service.TravelsService;
import com.etc.util.Message;
import com.etc.util.PageData;

@Controller
@RequestMapping(value = "infapi")
public class InformationController {

	@Resource
	private OrderService os;

	@Resource
	private TravelsService ts;

	@Resource
	private FriendService fs;

	@Resource
	private DynamicService ds;
	
	@Resource
	private Message msg;

	@RequestMapping(value = "travels/{userId}", method = RequestMethod.GET)
	public String travelsByUserid(@PathVariable(value = "userId") int userid, HttpServletRequest request) {
		List<Travels> list = ts.selectByUserid(userid);
		request.setAttribute("traveluserid", list);
		return "youji";
	}

	@RequestMapping(value = "friend/{userId}", method = RequestMethod.GET)
	// 响应json
	@ResponseBody
	public PageData<Friend> selectByPage(@RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "limit", defaultValue = "10") Integer limit,
			@RequestParam(value = "content", defaultValue = "") String content,
			@PathVariable(value = "userId") int userid) {
		PageData<Friend> pd = fs.selectByPage(page, limit, content, userid);
		pd.setCode(0);
		pd.setMsg("获取到数据咯！");
		return pd;
	}

	@RequestMapping(value = "dongtai/{userId}", method = RequestMethod.GET)
	public String dynamicByUserid(@PathVariable(value = "userId") int userid, HttpServletRequest request) {
		List<Dynamic> list = ds.selectByUserid(userid);
		request.setAttribute("dynamicuserid", list);
		return "dongtai";
	}
	
	@RequestMapping(value = "friend/{friendId}", method = RequestMethod.DELETE)
	public Message delFriend(@PathVariable(value = "friendId") int friendid) {
		boolean flag = fs.deleteByPrimaryKey(friendid);
		msg.setMsg("删除失败");
		if(flag) {
			msg.setMsg("删除成功");
		}
		return msg;
	}
}
